import { Component, OnInit } from '@angular/core';
import {FormGroup, FormBuilder, Validators} from '@angular/forms';

@Component({
  selector: 'app-reactive',
  templateUrl: './reactive.component.html',
  styleUrls: ['./reactive.component.less']
})
export class ReactiveComponent implements OnInit {

  form: FormGroup;
  info: Organization = new Organization();

  constructor(private fb: FormBuilder,
  ) { }

  ngOnInit() {
    this.initForm();
  }

  /*
   * 初始化响应式表单*/
  initForm() {
    if (!this.form) {
      this.form = this.fb.group({
        name: [null, [Validators.required]],
        area: [null, [Validators.required]],
        email: [null, [Validators.required]],
        phone: [null],
        address: [null]
      });
    }
  }

}

export class Organization {
  name: string;
  area: string;
  email: string;
  phone: string;
  address: string;
}
